/**
 * wave table is the instrument bank by sf2synth.js which base on web midi link.
 * because of we do not have enough time, so we use this wavetable to play bassline
 */
jweb.util.WaveTable = function() {
  this.appendEl = $('div#wavatable');
  this.subscriberId=null;
  this.sfurl = 'thirdparty/sf2synth/sf/A320U.sf2';
  this.wmlGainNode = null;
  this.wml = null;
  this.mute = false;
  this.start();
}
jweb.util.WaveTable.prototype= {
	onMessage:function(subj, msg, data) {
		if(subj == constants.midiMessage){
			if(this.mute) return ;
		}
	},
	start:function() {
		if(this.subscriberId==null) this.subscriberId='**';
		this.subscriberId = window.PageBus.subscribe('**', this, this.onMessage, null);
		
		//load web midi link
		this.wml = new SoundFont.WebMidiLink();
		var $wml=this.wml;
		this.wml.setLoadCallback(function(arraybuffer){
			$('div#container').unmask();
		});
		this.wml.setup(this.sfurl);
		window.PageBus.publish(constants.synth2Ready, {synth:$wml});
	},
	stop:function() {
		if(this.subscriberId!=null){
			window.PageBus.unsubscribe(this.subscriberId);
			this.subscriberId=null;
		}
	}
}